//
//  KYServerClient.h
//  KYServerClient
//
//  Created by mrj on 16/7/1.
//  Copyright © 2016年 ikaiyong. All rights reserved.
//

#import <Foundation/Foundation.h>

#define KY_SERVER_CLIENT [KYServerClient shareServerClient]
#define APP_KEY @"mmmmmmmm"
#define APP_KEY_ZBAR @"hmd98745"
#define APP_USERNAME @"d1"
#define APP_PASSWORD @"111111"
#define TYPEID @"3"

/**
 文件类型
 */
typedef NS_ENUM(NSInteger,FileType) {
    FileTypeImage,  //图片文件
    FileTypeAudio,   //录音文件
    FileTypeVideo       //视频文件
};

typedef void (^HttpReuqestSucceedBlock)(id object);
typedef void (^HttpRequestFailedBlock)(id object);

//请求方法
typedef NS_ENUM(NSInteger,IHealthServerRequestMethod)
{
    IHealthServerRequestMethodGET,
    IHealthServerRequestMethodPOST
};

typedef NS_ENUM(NSInteger, HubTipsName) {
    
    HubTipsHidden = 1,                     //不显示加载
    HubTipsShow,                           //正在加载
    HubTipsShowUpload,                     //上传中...
    HubTipsShowSave,                       //保存中...
    HubTipsShowLogin,                       //登录中...
    
};

@interface KYServerClient : NSObject
@property (nonatomic, strong) AFHTTPSessionManager   *sessionManager;
/**
 *  服务器客户端单例
 *
 *  @return 服务器客户端对象
 */
+ (KYServerClient*)shareServerClient;


/**
 *  发送http请求
 *
 *  @param method           请求方法
 *  @param URLString        路径
 *  @param parameters       参数
 *  @param pertreatment     预处理
 *  @param downloadProgress 进度
 *  @param success          成功回调
 *  @param failure          失败回调
 */
- (void)sendRequestMethod:(IHealthServerRequestMethod)method
                      URL:(NSString*)URLString
               parameters:(id)parameters
             pertreatment:(void(^)(void))pertreatment
                 progress:(void (^)(NSProgress *downloadProgress))downloadProgress
                  success:(void (^)(NSURLSessionDataTask *task, id  responseObject))success
                  failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure;



- ( NSURLSessionDataTask *)sendRequestPOST:(NSString *)URLString
                              pertreatment:(void(^)(void))pertreatment
                                parameters:( id)parameters
                 constructingBodyWithBlock:( void (^)(id <AFMultipartFormData> formData))block
                                  progress:( void (^)(NSProgress *uploadProgress))uploadProgress
                                   success:( void (^)(NSURLSessionDataTask *task, id  responseObject))success
                                   failure:( void (^)(NSURLSessionDataTask *  task, NSError *error))failure;
/**
 *  网络是否连接
 *
 *  @return 连接状态
 */
- (BOOL)isReachableNetwork;



/**
 *  发送POST请求
 *
 *  @param url             地址
 *  @param parameters      头信息
 *  @param model           返回model（nil 返回字典）
 *  @param completionBlock 成功块
 *  @param errorBlock      失败块
 */
-(void) sendPostWithURL:(NSString*)url
             parameters:(NSDictionary*)parameters
                toModel:(JSONModel *)model
            showHubName:(HubTipsName)tipsName
           onCompletion:(HttpReuqestSucceedBlock) completionBlock
                onError:(HttpRequestFailedBlock) errorBlock;

/**
 上传文件
 
 @param url url
 @param parameters 参数
 @param files 文件
 @param model model
 @param completionBlock 成功回调
 @param errorBlock 失败回调
 */
- (void)uploadFileURL:(NSString *)url
           parameters:(NSDictionary*)parameters
                files:(NSDictionary *)files
              toModel:(JSONModel *)model
            filesType:(FileType)filesType
         onCompletion:(HttpReuqestSucceedBlock) completionBlock
              onError:(HttpRequestFailedBlock) errorBlock;

//- (void)downLoadFileWithFileId


/**
 上传不同分类的多个图片
 
 @param url url
 @param parameters 参数
 @param fileArr 二维数组 或一维数组
 @param model model
 @param filesType 文件类型（视频或者音频）
 @param completionBlock 成功回调
 @param errorBlock 失败回调
 */
- (void)uploadFileURL:(NSString *)url
           parameters:(NSDictionary*)parameters
              fileArr:(NSMutableArray *)fileArr
              toModel:(JSONModel *)model
            filesType:(FileType)filesType
         onCompletion:(HttpReuqestSucceedBlock) completionBlock
              onError:(HttpRequestFailedBlock) errorBlock;


//下载图片
- (NSString *)getDownloadFileURL:(NSString *)url
                      parameters:(NSDictionary*)parameters;

- (NSURL*)getDownloadImageById:(NSString*)imageId isThumb:(NSString*)isThumb;
@end
